import java.util.Stack;

/**
 * @author Sebastian
 * @version 2.0
 * @date 2024/7/4 20:37
 */
// 最小栈 双栈解法
    //https://leetcode.cn/problems/min-stack/description/
public class MinStack1 {
    Stack<Integer> stk = new Stack<Integer>();
    Stack<Integer> minStk = new Stack<Integer>();

    public MinStack1(Stack<Integer> stk, Stack<Integer> minStk) {
        this.stk = stk;
        this.minStk = minStk;
    }

    public void push(int val) {
        stk.push(val);
        if (stk.isEmpty() || minStk.peek() >= val) {
            minStk.push(val);
        } else {
            minStk.push(minStk.peek());
        }
    }

    public void pop() {
        stk.pop();
        minStk.pop();
    }

    public int top() {
        return stk.peek();
    }

    public int getMin() {
        return minStk.peek();
    }
}
